<template>
  <div class="wrap">
    <!-- 专利字段 -->
    <template v-if="type == 'patent'">
      <h3>著录项</h3>
      <dl class="des-info">
        <dd>
          <span>申请号</span>
          <span>{{ publicInfo.apn || "--" }}</span>
        </dd>
        <dd>
          <span>申请日</span>
          <span>{{ publicInfo.apd || "--" }}</span>
        </dd>
        <dd>
          <span>公开/公告号</span>
          <span>{{ publicInfo.pn || "--" }}</span>
        </dd>
        <dd>
          <span>公开/公告日</span>
          <span>{{ publicInfo.isd || "--" }}</span>
        </dd>
        <dd>
          <span>申请人</span>
          <span>{{ handleKeyword(publicInfo.an) || "--" }}</span>
        </dd>
        <dd>
          <span>发明人</span>
          <span>{{ handleKeyword(publicInfo.in) || "--" }}</span>
        </dd>
        <dd>
          <span>CPC</span>
          <span>{{ handleKeyword(publicInfo.cpc) || "--" }}</span>
        </dd>
        <dd>
          <span>主分类号</span>
          <span
            >{{ publicInfo.ipcm }}（{{ publicInfo.ipc_kind || "--" }}）</span
          >
        </dd>
        <dd>
          <span>IPC</span>
          <span>{{ handleKeyword(publicInfo.ipc) || "--" }}</span>
        </dd>
        <dd>
          <span>专利类型</span>
          <span>{{ publicInfo.na || "--" }}</span>
        </dd>
        <dd>
          <span>法律状态</span>
          <span>{{ publicInfo.leg_det || "--" }}</span>
        </dd>
        <dd>
          <span>国家</span>
          <span>{{ codeToZh(publicInfo.nd) || "--" }}</span>
        </dd>
        <dd>
          <span>权利要求个数</span>
          <span>{{ publicInfo.acc || "--" }}</span>
        </dd>
        <dd>
          <span>技术价值度</span>
          <span>{{ Math.ceil(publicInfo.j || 0) }}</span>
        </dd>
        <dd>
          <span>代理机构</span>
          <span>{{ publicInfo.agency || "--" }}</span>
        </dd>
        <dd>
          <span>地址</span>
          <span>{{ publicInfo.ads || "--" }}</span>
        </dd>
      </dl>
      <h3>
        {{
          publicInfo.na && publicInfo.na.indexOf("外观") > -1 ? "说明" : "摘要"
        }}
      </h3>
      <p
        class="abstract"
        v-html="publicInfo.abst || publicInfo.abst_en || publicInfo.abst_zh"
      ></p>
      <!-- <p
        v-if="isJapanese(publicInfo.abst)"
        class="abstract"
        v-html="publicInfo.abst_zh || publicInfo.abst_en"
      ></p> -->
      <p
        v-if="!isChinese(publicInfo.abst)"
        class="abstract"
        v-html="publicInfo.abst_zh || publicInfo.abst_en"
      ></p>
    </template>

    <!-- 文献字段展示 -->
    <template v-if="type == 'paper'">
      <!-- 题录信息 -->
      <template v-if="btnActive == 0">
        <h3>题录信息</h3>
        <dl class="des-info">
          <dd>
            <span>机构</span>
            <span>{{ publicInfo.organStr || "--" }}</span>
            <!-- <span >{{handleAuthor(publicInfo.organ)}}</span> -->
          </dd>
          <dd>
            <span>作者</span>
            <span v-html="publicInfo.authorStr"></span>
            <!-- <span >{{handleAuthor(publicInfo.author)}}</span> -->
          </dd>
          <dd>
            <span>发表时间</span>
            <span>{{ publicInfo.year || "--" }}</span>
          </dd>
          <dd>
            <span>DOI</span>
            <span>{{ publicInfo.doi || "--" }}</span>
          </dd>
          <dd>
            <span>期刊</span>
            <span>{{ publicInfo.venue_name || "--" }}</span>
          </dd>
          <dd>
            <span>学科</span>
            <span>{{ publicInfo.category || "--" }}</span>
          </dd>
          <dd>
            <span>关键词</span>
            <span>{{ handleKeyword(publicInfo.keywords_zh) || "--" }}</span>
          </dd>
          <dd>
            <span>论文类型</span>
            <span>期刊论文</span>
            <!-- <span>{{ publicInfo.type }}</span> -->
          </dd>
          <dd>
            <span>国家</span>
            <span>{{ country || "--" }}</span>
            <!-- <span>{{ publicInfo.country }}</span> -->
          </dd>
          <!-- <dd>
            <span>基金资助</span>
            <span>{{ handleAuthor(publicInfo.fund) }}</span>
          </dd> -->
          <dd style="width: 100%">
            <span>摘要</span>
            <span
              v-html="publicInfo.abstract || publicInfo.abstract_ori"
            ></span>
          </dd>
          <dd style="width: 100%" v-if="!isChinese(publicInfo.abstract_ori)">
            <span></span>
            <span v-html="publicInfo.abstract_zh"></span>
          </dd>
        </dl>
      </template>
      <!-- 其他信息 -->
      <!-- <template v-if="btnActive == 1">
        <h3>其他信息</h3>
        <dl class="des-info">
          <dd>
            <span>被引用次数</span>
            <span >{{publicInfo.citation_count}}</span>
          </dd>
          <dd>
            <span>引用影响力</span>
            <span >{{publicInfo.fwci}}</span>
          </dd>
          <dd>
            <span>引用百分位</span>
            <span >{{publicInfo.citation_percentile}}</span>
          </dd>
          <dd>
            <span>期刊影响力</span>
            <span >{{publicInfo.citescore}}</span>
          </dd>
          <dd>
            <span>研究主题</span>
            <span >{{handleKeyword(publicInfo.topic)}}</span>
          </dd>
          <dd>
            <span>主题热度值</span>
            <span >{{publicInfo.topic_pp}}</span>
          </dd>
          <dd style="width:100%">
            <span>参考文献</span>
            <span >{{handleKeyword(publicInfo.references_text)}}</span>
          </dd>
        </dl>
      </template> -->
    </template>
    <!-- 成果字段展示 -->
    <template v-if="type == 'achieve'">
      <!-- 基本信息 -->
      <template v-if="btnActive == 0">
        <dl class="des-info">
          <dd style="width: 100%" v-show="publicInfo.achievement_institution">
            <span>完成单位:</span>
            <span>{{ publicInfo.achievement_institution }}</span>
          </dd>
          <dd style="width: 100%" v-show="publicInfo.contrib_full_name">
            <span>成果完成人:</span>
            <span>{{ publicInfo.contrib_full_name }}</span>
          </dd>
          <dd style="width: 100%" v-show="publicInfo.achievement_type">
            <span>成果类别:</span>
            <span>{{ publicInfo.achievement_type }}</span>
          </dd>
          <dd style="width: 100%" v-show="publicInfo.achievement_field">
            <span>技术领域:</span>
            <span>{{ handleKeyword(publicInfo.achievement_field) }}</span>
          </dd>
          <dd style="width: 100%" v-show="publicInfo.achievement_stage">
            <span>成果水平:</span>
            <span>{{ publicInfo.achievement_stage }}</span>
          </dd>
          <dd style="width: 100%" v-show="publicInfo.achievement_subject">
            <span>学科:</span>
            <span>{{ publicInfo.achievement_subject }}</span>
          </dd>
          <dd style="width: 100%" v-show="publicInfo.achievement_industry">
            <span>行业类别:</span>
            <span>{{
              (publicInfo.achievement_industry || []).join("、")
            }}</span>
          </dd>
          <dd style="width: 100%" v-show="publicInfo.assess_format">
            <span>评价形式:</span>
            <span>{{ publicInfo.assess_format }}</span>
          </dd>
          <dd style="width: 100%" v-show="publicInfo.keywords">
            <span>关键词:</span>
            <span>{{ publicInfo.keywords }}</span>
          </dd>
          <dd style="width: 100%" v-show="publicInfo.registered_date">
            <span>入库时间:</span>
            <span>{{ publicInfo.registered_date }}</span>
          </dd>
          <dd style="width: 100%" v-show="publicInfo.research_date">
            <span>研究起止时间:</span>
            <span>{{ publicInfo.research_date }}</span>
          </dd>
          <dd style="width: 100%" v-show="publicInfo.achievement_profile">
            <span>成果简介:</span>
            <span>{{ publicInfo.achievement_profile }}</span>
          </dd>
        </dl>
      </template>
    </template>
    <!-- 项目字段展示 -->
    <template v-if="type == 'project'">
      <!-- 基本信息 -->
      <template v-if="btnActive == 0">
        <dl class="des-info">
          <dd>
            <span>项目编号:</span>
            <span>{{ publicInfo.batch_no }}</span>
          </dd>
          <dd>
            <span>国家:</span>
            <span>{{ publicInfo.project_country }}</span>
          </dd>
          <dd>
            <span>项目经费(万元):</span>
            <span
              >${{ publicInfo.grants }}USD ({{ publicInfo.grants }}美元)</span
            >
          </dd>
          <dd>
            <span>资助机构:</span>
            <span>{{ publicInfo.fund_inst }}</span>
          </dd>
          <dd>
            <span>承担机构:</span>
            <span>{{ publicInfo.support_inst }}</span>
          </dd>
          <dd>
            <span>项目负责人:</span>
            <span>{{ publicInfo.pro_leader }}</span>
          </dd>
          <dd>
            <span>项目起始时间:</span>
            <span>{{ publicInfo.begin_date }}</span>
          </dd>
          <dd>
            <span>项目结束时间:</span>
            <span>{{ publicInfo.end_date }}</span>
          </dd>
          <dd>
            <span>学科分类:</span>
            <span>{{ publicInfo.pro_type }}</span>
          </dd>
          <dd>
            <span>数据类型:</span>
            <span>{{ publicInfo.data_type }}</span>
          </dd>
          <dd>
            <span>研究领域号:</span>
            <span>{{ publicInfo.appr_no }}</span>
          </dd>
          <dd>
            <span>研究领域:</span>
            <span>
              {{
                publicInfo.app_name_one.length == 0
                  ? " "
                  : publicInfo.app_name_one.join("、")
              }}
              {{
                publicInfo.app_name_two.length == 0
                  ? " "
                  : publicInfo.app_name_two.join("、")
              }}
              {{
                publicInfo.app_name_three.length == 0
                  ? " "
                  : publicInfo.app_name_three.join("、")
              }}
            </span>
          </dd>
          <dd>
            <span>来源:</span>
            <span>{{ publicInfo.datasource }}</span>
          </dd>
          <dd>
            <span>关键字:</span>
            <span>{{ publicInfo.keywords_ori }}</span>
          </dd>
        </dl>
        <div class="des-info">
          <h3>摘要:</h3>
          <span
            v-html="publicInfo.ab_ori || publicInfo.ab_en || publicInfo.ab_cn"
          ></span>
          <br />
          <!-- <span
            v-if="isJapanese(publicInfo.ab_ori)"
            v-html="publicInfo.ab_cn || publicInfo.ab_en"
          ></span> -->
          <span
            v-if="!isChinese(publicInfo.ab_ori)"
            v-html="publicInfo.ab_cn || publicInfo.ab_en"
          ></span>
        </div>
      </template>
    </template>
    <!-- 标准字段展示 -->
    <template v-if="type == 'standard'">
      <!-- 基本信息 -->
      <template v-if="btnActive == 0">
        <p class="standard-tit" style="margin-top: 15px;">基本信息</p>
        <dl
          class="des-info"
          v-show="
            ['国家标准', '行业标准', '地方标准', '团体标准'].indexOf(
              publicInfo.type
            ) > -1
          "
        >
          <dd>
            <span>标准类型:</span>
            <span>{{ publicInfo.type || "--" }}</span>
          </dd>
          <dd>
            <span>标准号:</span>
            <span>{{ publicInfo.code || "--" }}</span>
          </dd>
          <dd>
            <span>标准状态:</span>
            <span>{{ publicInfo.status || "--" }}</span>
          </dd>
          <dd v-show="publicInfo.type == '国家标准'">
            <span>标准性质:</span>
            <span>{{ publicInfo.grants || "--" }}</span>
          </dd>
          <dd v-show="publicInfo.type == '行业标准'">
            <span>行业领域:</span>
            <span>{{ publicInfo.industry_field || "--" }}</span>
          </dd>
          <dd v-show="publicInfo.type == '地方标准'">
            <span>省市区:</span>
            <span>{{ publicInfo.source || "--" }}</span>
          </dd>
          <dd v-show="publicInfo.type == '团体标准'">
            <span>国民经济分类:</span>
            <span>{{ publicInfo.industry || "--" }}</span>
          </dd>
          <dd>
            <span>标准类别:</span>
            <span>{{ publicInfo.category || "--" }}</span>
          </dd>
          <dd>
            <span>中国标准分类号:</span>
            <span>{{ publicInfo.zh_class || "--" }}</span>
          </dd>
          <dd>
            <span>发布日期:</span>
            <span>{{ publicInfo.issue_date || "--" }}</span>
          </dd>
          <dd>
            <span>国际标准分类号:</span>
            <span>{{ publicInfo.in_class || "--" }}</span>
          </dd>
          <dd>
            <span>实施日期:</span>
            <span>{{ publicInfo.imp_date || "--" }}</span>
          </dd>
          <dd
            v-show="
              ['国家标准', '行业标准', '地方标准'].indexOf(publicInfo.type) > -1
            "
          >
            <span>归口单位:</span>
            <span>{{ publicInfo.tech_commitees || "--" }}</span>
          </dd>
          <dd v-show="publicInfo.type == '团体标准'">
            <span>团体名称:</span>
            <span>{{ publicInfo.team || "--" }}</span>
          </dd>
          <dd v-if="publicInfo.status == '废止'">
            <span>废止日期:</span>
            <span>{{ publicInfo.abo_date || "--" }}</span>
          </dd>
          <dd v-show="publicInfo.type == '国家标准'">
            <span>执行单位:</span>
            <span>{{ publicInfo.exec_unit || "--" }}</span>
          </dd>
          <dd v-show="['行业标准', '地方标准'].indexOf(publicInfo.type) > -1">
            <span>批准发布部门:</span>
            <span>{{ publicInfo.issue_unit || "--" }}</span>
          </dd>
          <dd
            v-show="
              publicInfo.alt_standards &&
              publicInfo.status != '现行' &&
              ['国家标准', '行业标准'].indexOf(publicInfo.type) > -1
            "
          >
            <span>代替标准:</span>
            <span>{{ publicInfo.alt_standards || "--" }}</span>
          </dd>
          <dd v-show="publicInfo.type == '地方标准'">
            <span>制修订:</span>
            <span>{{ publicInfo.revise_type || "--" }}</span>
          </dd>
          <dd v-show="publicInfo.type == '国家标准'">
            <span>主管部门:</span>
            <span>{{ publicInfo.com_department || "--" }}</span>
          </dd>
          <dd v-show="['行业标准', '地方标准'].indexOf(publicInfo.type) > -1">
            <span>行业分类:</span>
            <span>{{ publicInfo.industry || "--" }}</span>
          </dd>
          <dd v-show="publicInfo.type == '团体标准'">
            <span>是否包含专利信息:</span>
            <span>{{ publicInfo.has_patent || "--" }}</span>
          </dd>
          <dd v-show="publicInfo.type == '团体标准'">
            <span>标准文本:</span>
            <span>{{ publicInfo.open_status || "--" }}</span>
          </dd>
        </dl>
        <div v-show="publicInfo.type == '企业标准'">
          <dl class="des-info">
            <dd>
              <span>标准类型:</span>
              <span>{{ publicInfo.type || "--" }}</span>
            </dd>
            <dd>
              <span>标准号:</span>
              <span>{{ publicInfo.code || "--" }}</span>
            </dd>
            <dd>
              <span>标准状态:</span>
              <span>{{ publicInfo.status || "--" }}</span>
            </dd>
            <dd v-show="publicInfo.type == '国家标准'">
              <span>发布日期:</span>
              <!-- <span>{{ publicInfo. || "--" }}</span> -->
            </dd>
          </dl>
          <p class="standard-tit">起草单位</p>
          <p class="s-c">
            {{ publicInfo.drafting_unit || "--" }}
          </p>
          <p class="standard-tit">执行该标准的产品信息</p>
          <el-table :data="patentData" style="width: 100%">
            <el-table-column type="index" label="序号" width="50">
            </el-table-column>
            <el-table-column prop="" label="产品名称"> </el-table-column>
            <el-table-column prop="" label="通用名"> </el-table-column>
            <el-table-column prop="" label="品牌"> </el-table-column>
            <el-table-column prop="" label="条码"> </el-table-column>
            <el-table-column prop="" label="规格"> </el-table-column>
            <el-table-column prop="" label="型号"> </el-table-column>
            <el-table-column prop="" label="分类" width="300">
            </el-table-column>
          </el-table>
          <p class="standard-tit">承诺书</p>
          <p class="s-c" v-html="publicInfo.commitment || '--'"></p>
        </div>
        <div v-show="['行业标准', '地方标准'].indexOf(publicInfo.type) > -1">
          <p class="standard-tit">备案信息</p>
          <dl class="des-info">
            <dd>
              <span>备案号:</span>
              <span>{{ publicInfo.record_no || "--" }}</span>
            </dd>
            <dd>
              <span>备案日期:</span>
              <span>{{ publicInfo.record_date || "--" }}</span>
            </dd>
          </dl>
        </div>
        <div
          v-show="
            ['国家标准', '行业标准', '地方标准', '团体标准'].indexOf(
              publicInfo.type
            ) > -1
          "
        >
          <p class="standard-tit">起草单位</p>
          <p class="s-c">
            {{ publicInfo.drafting_unit || "--" }}
          </p>
          <p class="standard-tit">起草人</p>
          <p class="s-c">
            {{ publicInfo.draftsman || "--" }}
          </p>
        </div>
        <div v-show="publicInfo.type == '国家标准'">
          <p class="standard-tit">简介</p>
          <p class="s-c" v-html="publicInfo.introduction || '--'"></p>
        </div>
        <div
          v-show="
            ['行业标准', '地方标准', '团体标准'].indexOf(publicInfo.type) > -1
          "
        >
          <p class="standard-tit">适用范围</p>
          <p class="s-c" v-html="publicInfo.scope || '--'"></p>
        </div>
        <div v-show="publicInfo.type == '团体标准'">
          <p class="standard-tit">主要技术内容</p>
          <p class="s-c" v-html="publicInfo.tech_content || '--'"></p>
          <p class="standard-tit">承诺书</p>
          <p class="s-c" v-html="publicInfo.commitment || '--'"></p>
        </div>
      </template>
    </template>
  </div>
</template>

<script>
import { thousands } from "@/utils/utils";
import countryJson from "@/utils/mock/country.json";
export default {
  props: {
    publicInfo: {
      type: Object,
    },
    type: {
      type: String,
    },
    btnActive: {
      type: Number,
    },
  },
  data() {
    return {
      country: "",
      patentData: [],
    };
  },
  watch: {
    publicInfo: {
      handler() {
        this.handleAuthors();
      },
      deep: true,
      immediate: true,
    },
  },
  mounted() {
    if (this.type == "project") {
      this.publicInfo.format_grants = thousands(
        Number(this.publicInfo.format_grants)
      );
      this.publicInfo.grants = thousands(
        Number(this.publicInfo.grants.split("(")[0])
      );
    }
    this.handleAuthors();
  },
  methods: {
    handleAuthors() {
      if (this.type == "paper") {
        const { authorStr, organStr } = this.getAuthors(
          this.publicInfo.authors
        );
        this.publicInfo.authorStr = authorStr;
        this.publicInfo.organStr = organStr;
      }
    },
    // 判断是否为中文
    isChinese(str) {
      // if (!str) {
      //   return false;
      // } else {
      //   var regEx = "[\u4e00-\u9fa5]"; //部分为中文
      //   // var regEx = /^[\u4e00-\u9fa5]+$/;  //全部为中文
      //   let flg = false;
      //   if (str.match(regEx)) flg = true;
      //   return flg;
      // }
      return /[\u4E00-\u9FA5]+/g.test(str);
    },
    // 判断是否为日文
    isJapanese(str) {
      if (!str) {
        return false;
      } else {
        var regEx = "[\u0800-\u4e00]"; //部分为日文
        let flg = false;
        if (str.match(regEx)) flg = true;
        return flg;
      }
    },
    getAuthors(list) {
      let authorStr = "",
        organList = [],
        organStr = "";
      list.forEach((li, idx) => {
        if (this.country == "") {
          this.country = li.country;
        }
        if (li.org_zh || li.org) {
          if (organList.indexOf(li.org_zh || li.org) == -1) {
            organList.push(li.org_zh || li.org);
          }
          authorStr += `${idx > 0 ? "，" : ""}${li.name_zh || li.name}<sup>${
            organList.indexOf(li.org_zh || li.org) + 1
          }</sup>`;
        } else {
          authorStr += `${idx > 0 ? "，" : ""}${li.name_zh || li.name}`;
        }
      });
      organList.forEach((list, idx) => {
        organStr += `${idx == 0 ? "" : "，"}${idx + 1}.${list}`;
      });
      if (authorStr == "") {
        authorStr = "--";
      }
      if (organStr == "") {
        organStr = "--";
      }
      return { authorStr, organStr };
    },
    handleAuthor(arr) {
      let list = [];
      arr &&
        arr.map((item) => {
          list.push(item);
        });
      return list.join("、");
    },
    handleKeyword(arr) {
      if (Array.isArray(arr)) {
        return arr.join("、");
      }
    },
    // 国家地区code码转中文
    codeToZh(key) {
      let obj = countryJson.countrs.find((b) => b.code === key);
      // console.log(obj);
      return obj?.cn || "--";
    },
  },
};
</script>

<style lang="scss" scoped>
.wrap {
  position: relative;
  padding-left: 20px;
  h3 {
    height: 42px;
    margin-top: 0;
    margin-bottom: 16px;
    line-height: 42px;
    font-size: 14px;
    font-weight: bold;
    color: $color1;
  }
  .row {
    position: relative;
    display: inline-flex;
    flex-wrap: wrap;
    width: 90%;
    dd {
      display: inline-flex;
      justify-content: center;
      width: 100%;
      margin-bottom: 7px;
      span {
        min-width: 0;
        line-height: 14px;
        font-size: 12px;
        &:nth-of-type(1) {
          width: 125px;
          color: $color6;
        }
        &:nth-of-type(2) {
          flex: 1;
          // display: inline-flex;
          min-height: 40px;
          padding-right: 10px;
          color: $color1;
          word-break: break-all;
          word-wrap: break-word;
        }
      }
    }
  }
  .standard-tit {
    border-left: 4px solid $mainColor;
    font-weight: bold;
    padding: 2px 5px;
    margin-bottom: 20px;
  }
  .s-c {
    margin-bottom: 20px;
    line-height: 25px;
    font-size: 12px;
    color: $color1;
    word-break: break-all;
    word-wrap: break-word;
    text-indent: 2em;
  }
  .des-info {
    position: relative;
    display: inline-flex;
    flex-wrap: wrap;
    width: 100%;
    .ab_cn_title {
      font-weight: 600;
      line-height: 0.4rem;
    }
    dd {
      display: inline-flex;
      justify-content: center;
      width: 50%;
      margin-bottom: 7px;
      &.flex24 {
        width: 100%;
      }
      span {
        min-width: 0;
        line-height: 14px;
        font-size: 12px;
        &:nth-of-type(1) {
          width: 125px;
          line-height: 25px;
          color: $color6;
        }
        &:nth-of-type(2) {
          flex: 1;
          // display: inline-flex;
          min-height: 40px;
          line-height: 25px;
          padding-right: 10px;
          color: $color1;
          word-break: break-all;
          word-wrap: break-word;
        }
      }
    }
  }
  .abstract {
    width: 90%;
    line-height: 1.5;
    margin: 10px 0;
    text-indent: 2em;
    font-size: 12px;
    color: $color143;
  }
}
</style>